<template>
  <el-container>
    <el-header>
      <!--logo区域-->
      <div class="logo-box" :style="{ width: collapse ? '64px' : '260px' }">
        <div class="logo-pic">
          <img src="../assets/logo.png" alt="" />
        </div>
        <div class="logo-title">云上博物馆后台系统</div>
      </div>
      <!--菜单折叠按钮-->
      <div class="menu-change-box" @click="collapseChange">
        <i v-if="collapse">
          <el-icon><Fold /></el-icon>
        </i>
        <i v-else>
          <el-icon><Expand /></el-icon>
        </i>
      </div>
      <!-- 个人头像 -->
      <div class="avatar-box">
        <img src="@/assets/logo.png" />
        <el-dropdown @command="handleCommand">
          <span class="el-dropdown-link">
            Admin<el-icon class="el-icon--right"><arrow-down /></el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="a">退出登录</el-dropdown-item>
              <el-dropdown-item command="e" divided>修改密码</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside :width="collapse ? '64px' : '260px'">
        <el-menu
          background-color="#fff"
          text-color="#777"
          active-text-color="#5fa4f6"
          unique-opened
          router
        >
          <template v-for="item in menuList" :key="item.id">
            <template v-if="item.children[0]">
              <el-sub-menu :index="item.id + ''">
                <!-- 一级菜单 -->
                <template #title>
                  <el-icon><Grid /></el-icon>
                  <span>{{ item.authName }}</span>
                </template>
                <!-- 二级菜单 -->
                <template v-for="subItem in item.children" :key="subItem.id">
                  <el-menu-item :index="subItem.path + ''">
                    <el-icon><ArrowLeftBold /></el-icon>
                    <template #title> {{ subItem.authName }}</template>
                  </el-menu-item>
                </template>
              </el-sub-menu>
            </template>

            <!-- 这个用于只有一级菜单的 -->
            <template v-else>
              <el-menu-item :index="item.path" :key="item.id">
                <template #title>
                  <el-icon><Discount /></el-icon>
                  <span>{{ item.authName }}</span>
                </template>
              </el-menu-item>
            </template>
          </template>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref } from 'vue'
const menuList = [
  {
    id: 0,
    authName: '首页',
    path: '/index',
    children: []
  },
  {
    id: 1,
    authName: '用户管理',
    children: [
      {
        id: 11,
        authName: '用户列表',
        path: '/user',
        children: []
      }
    ]
  },
  {
    id: 2,
    authName: '藏品管理',
    children: [
      {
        id: 21,
        authName: '藏品列表',
        path: '/collection',
        children: []
      },
      {
        id: 22,
        authName: '添加藏品',
        path: '/collection/add',
        children: []
      }
    ]
  },
  {
    id: 3,
    authName: '公告管理',
    children: [
      {
        id: 31,
        authName: '公告列表',
        path: '/announcement',
        children: []
      },
      {
        id: 32,
        authName: '发布公告',
        path: '/announcement/add',
        children: []
      }
    ]
  },
  {
    id: 4,
    authName: '数据分析',
    children: [
      {
        id: 41,
        authName: '藏品数据',
        path: '/data-analysis',
        children: []
      }
    ]
  }
]
// const icon = {
//   0: 'Grid',
//   1: 'user',
//   2: 'Mug',
//   3: 'ChatDotSquare',
//   4: 'PieChart'
// }
let collapse = ref(false)
const collapseChange = () => {
  collapse.value = !collapse.value
}
</script>

<style lang="scss" scoped>
.el-container {
  height: 100%;
  width: 100%;
}
.el-header {
  background-color: #fff;
  display: flex;
  align-items: center;
  padding: 0;
  border: none;
  margin: 0;
  position: relative;
  height: 60px;
  overflow: hidden;
  box-shadow: 0 1px 5px rgba(55, 122, 255, 0.3);
  .logo-box {
    background-image: linear-gradient(to right, #0659ff, #3f80ff); // 渐变色
    display: flex;
    align-items: center;
    height: 100%;
    width: 200px;
    overflow: hidden;
    transition: all 0.38s;
    .logo-pic {
      height: 100%;
      width: 64px;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 7px;
      box-sizing: border-box;

      img {
        height: 50px;
        width: 50px;
        border-radius: 5px;
      }
    }
    .logo-title {
      text-align: center;
      align-items: center;
      height: 100%;
      width: 196px;
      height: 90px;
      line-height: 90px;
      width: 100px;
      color: #fff;
      font-size: 20px;
      word-break: keep-all;
    }
  }

  .avatar-box {
    position: absolute;
    right: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: row;

    img {
      width: 40px;
      height: 40px;
      border-radius: 100%;
      margin-right: 10px;
    }
  }
}

.el-aside {
  background-color: #fff;
  box-shadow: 0 1px 5px rgba(55, 122, 255, 0.3);
  z-index: 999;
  transition: all 0.38s;
}
</style>
